
const _requried = { required: true, trigger: 'blur', message: '该项为必选项' }
const _minMax = (min, max) => ({ min, max, trigger: 'blur', message: `内容为${min}-${max}个字符` })

const _noValue = { trigger: 'blur', validate: (rule, value, callback) => value.trim().length > 0 ? callback() : callback(new Error('请填写内容')) }

const _email = { type: 'email', message: '请输入正确的邮箱地址', trigger: ['blur', 'change'] }

// 发布文章页面的校验规则
export const addArticleRules = {
  title: [
    _requried,
    _minMax(1, 30)
  ],
  cate_id: [
    _requried
  ],
  content: [_requried, _noValue],
  cover_img: [_requried]
}

// 用户详情
export const userInfoRules = {
  nickname: [
    _requried,
    _minMax(1, 10)
  ],
  email: [
    _requried,
    _email
  ]
}

// 重置密码
export const resetPassword = {
  old_pwd: [_requried, _minMax(6, 18)],
  new_pwd: [_requried, _minMax(6, 18)],
  re_pwd: [_requried, _minMax(6, 18)]
}
